<?php 
/**
 * SWFUpload 视图助手
 * 
 * 方便调用SWFUpload文件上传组件
 * 
 * @example
 * 必须包含进 swfupload.js, swfupload.queue.js, fileprogress.js, handlers.js 四个核心JS
 * 
 * echo $this->headScript()->appendFile($this->baseUrl().'/swfupload/swfupload.js')
    	->appendFile($this->baseUrl().'/js/swfupload.queue.js')
    	->appendFile($this->baseUrl().'/js/fileprogress.js')
    	->appendFile($this->baseUrl().'/js/handlers.js')
    	->appendScript($this->SWFUpload('/manager/index/upload', 100), 'text/javascript');
 * 
 * 
 * HTML的格式，样式自定义
 * <form id="form1" action="javascript:void(null)" method="post" enctype="multipart/form-data">
	<div class="fieldset flash" id="fsUploadProgress">
		<span class="legend"></span>
	</div>
	<span id="spanButtonPlaceHolder"></span>
	<button id="btnCancel" onclick="clearSuccessUpload(swfu);">重新上传</button>
   </form>
 * 
 * @author 高强
 *
 */
class Custom_View_Helper_Manager_SWFUpload extends Zend_View_Helper_Abstract
{
	/**
	 * 生成上传组件Javascript代码
	 * 
	 * @param string  $upload_url   上传服务器端路径
	 * @param integer $upload_limit 上传数量
	 * 
	 * @return mixed
	 */
	public function SWFUpload($upload_url, $upload_limit = 1)
	{
		
		$swfupload = "
			var swfu;
			window.onload = function() {
				var settings = {
					flash_url :\"{$this->view->baseUrl()}/swfupload/swfupload.swf\",
					upload_url : \"".$this->view->baseUrl().$upload_url."\",
					post_params: {\"PHPSESSID\" : \"".session_id()."\"},
					file_size_limit : \"100 MB\",
					file_types : \"*.*\",
					file_types_description : \"All Files\",
					file_upload_limit : ".$upload_limit.",
					file_queue_limit : 0,
					custom_settings : {
						progressTarget : \"fsUploadProgress\",
						cancelButtonId : \"btnCancel\"
					},
					debug: false,
	
					button_image_url: \"{$this->view->baseUrl()}/theme/manager/default/images/button01.png\",
					button_width: \"78\",
					button_height: \"24\",
					button_placeholder_id: \"spanButtonPlaceHolder\",
					button_text: '<span class=\"theFont\">文件上传</span>',
					button_text_style: \".theFont { font-size: 12; }\",
					button_text_left_padding: 17,
					button_text_top_padding: 1,
					
					file_queued_handler : fileQueued,
					file_queue_error_handler : fileQueueError,
					file_dialog_complete_handler : fileDialogComplete,
					upload_start_handler : uploadStart,
					upload_progress_handler : uploadProgress,
					upload_error_handler : uploadError,
					upload_success_handler : uploadSuccess,
					upload_complete_handler : uploadComplete,
					queue_complete_handler : queueComplete
				};
							
			    swfu = new SWFUpload(settings);
		    };
		";
		
		$swfupload = str_replace("\n", "", $swfupload);
		$swfupload = str_replace("\t", "", $swfupload);
		$swfupload = str_replace("\r", "", $swfupload);
		
		return $swfupload;
	}
}